package com.powerunion.datacollection.service;

import java.util.List;

import net.sf.json.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.powerunion.datacollection.common.SystemException;
import com.powerunion.datacollection.dao.CascadeFieldDao;
import com.powerunion.datacollection.dao.DaoFactory;
import com.powerunion.util.log.LogHelper;

public class CascadeFieldManager {
	private static Logger logger = LogHelper.getInstance().getLogger(
			CascadeFieldManager.class);
	private CascadeFieldDao dao = null;

	public CascadeFieldManager() {
		super();
		this.dao = (CascadeFieldDao) DaoFactory.getInstance().getDao(
				CascadeFieldDao.class);
	}

	public boolean save(List formFields,String formId) throws Exception {
		// 参数为空
		if (formFields == null) {
			String[] args = { "formFields" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter formFields NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		
		// 参数为空
		if (StringUtils.isEmpty(formId)) {
			String[] args = { "formId" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter formId NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		
		return this.dao.save(formFields, formId);
	}
	
	public boolean delete(String formId) throws Exception{
		// 参数为空
		if (StringUtils.isEmpty(formId)) {
			String[] args = { "formId" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter formId NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		return this.dao.delete(formId);
	}
	
	public List getCascadeFields(String formId) throws Exception{
		if (StringUtils.isEmpty(formId)) {
			String[] args = { "formId" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter formId NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		List fields = this.dao.getCascadeFields(formId);

		return fields;
	}
	
	
}
